#!/usr/bin/ruby
# vi:ft=ruby

require 'rubygems'
require 'active_record'
require 'active_support'
#require 'json'

ActiveRecord::Base.establish_connection(
    :adapter => 'mysql',
    :database => 'hhac',
    :username => 'hhac',
    :password => 'iamharmless',
    :host => 'localhost')

class Movie < ActiveRecord::Base
    set_table_name 'videos'
end

class User < ActiveRecord::Base
end

list = []
Movie.all.each do |movie|
  umovie = {
    "id" => movie.id,
    "title" => movie.title,
    "tags" => movie.tags,
    "description" => movie.description,
    "user" => User.find(movie.owner).name
  }
  list << umovie
end

#### Start writing response...
puts "Content-Type: text/plain; charset=utf-8\n\n"
puts list.to_json
